# -*- coding: utf-8 -*-
# https://blog.csdn.net/weixin_52040868
# 公众号：测个der
# 微信：qing_an_an

from PyQt5.QtWidgets import *
import sys


class Stack(QWidget):
    def __init__(self):
        super(Stack, self).__init__()
        # self.setGeometry(300, 50, 10, 10)
        self.setWindowTitle("StackedWidget 示例")

        self.leftlist = QListWidget()
        self.leftlist.insertItem(0, "联系方式")
        self.leftlist.insertItem(1, "个人信息")
        self.leftlist.insertItem(2, "教育程度")

        self.stack1 = QWidget()
        self.stack2 = QWidget()
        self.stack3 = QWidget()

        self.stack1UI()
        self.stack2UI()
        self.stack3UI()

        # 在QStackedWidget对象中填充了三个子控件
        self.Stack = QStackedWidget(self)
        self.Stack.addWidget(self.stack1)
        self.Stack.addWidget(self.stack2)
        self.Stack.addWidget(self.stack3)

        # 水平布局，添加部件到布局中
        hBox = QHBoxLayout(self)
        hBox.addWidget(self.leftlist)
        hBox.addWidget(self.Stack)
        self.setLayout(hBox)
        # 关联槽从而改变堆叠控件
        self.leftlist.currentRowChanged.connect(self.dispaly)

    def stack1UI(self):
        layout = QFormLayout()
        layout.addRow("姓名", QLineEdit())
        layout.addRow("地址", QLineEdit())
        # 放入stack1布局中
        self.stack1.setLayout(layout)

    def stack2UI(self):
        layout = QFormLayout()
        sex = QHBoxLayout()
        sex.addWidget(QRadioButton("男"))
        sex.addWidget(QRadioButton("女"))
        layout.addRow(QLabel("性别"), sex)
        layout.addRow("生日", QLineEdit())
        # 放入stack2布局中
        self.stack2.setLayout(layout)

    def stack3UI(self):
        layout = QHBoxLayout()
        layout.addWidget(QLabel("科目"))
        layout.addWidget(QCheckBox("物理"))
        layout.addWidget(QCheckBox("高数"))
        # 放入stack3布局中
        self.stack3.setLayout(layout)

    def dispaly(self, i):
        # 设置当前可见的选项卡的索引
        self.Stack.setCurrentIndex(i)


if __name__ == '__main__':
    app = QApplication(sys.argv)
    stack = Stack()
    stack.show()
    sys.exit(app.exec_())
